home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / memory / xms200je / xmstime.cpp < prev    next >
C/C++ Source or Header  |  1993-11-22  |  4KB  |  119 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //      XMSTIME.CPP: timing test for XMS class.
  4. //      Copyright (c) J.English 1993.
  5. //      Author's address: je@unix.brighton.ac.uk
  6. //
  7. //      Permission is granted to use copy and distribute the
  8. //      information contained in this file provided that this
  9. //      copyright notice is retained intact and that any software
  10. //      or other document incorporating this file or parts thereof
  11. //      makes the source code for the library of which this file
  12. //      is a part freely available.
  13. //
  14. //--------------------------------------------------------------------------
  15. //
  16. //      Revision history:
  17. //      2.0     Nov 1993        Initial coding
  18. //
  19. //--------------------------------------------------------------------------
  20.  
  21. #include "xms.h"
  22. #include "doserror.h"
  23. #include <stdio.h>
  24. #include <dos.h>
  25. #include <limits.h>
  26.  
  27. //--------------------------------------------------------------------------
  28. //
  29. //      Global data.
  30. //
  31. DOSerror e;             // guard against critical errors and control-breaks
  32. long size;              // XMS transfer size in bytes
  33. const int lapse = 91;   // timer ticks per test (91 ticks = 5 seconds)
  34. volatile long far* timer = (volatile long far*) MK_FP(0x40,0x6C);
  35.                         // pointer to tick counter in BIOS data area
  36.  
  37. //--------------------------------------------------------------------------
  38. //
  39. //      Display statistics.
  40. //
  41. void stats (long loops)
  42. {
  43.     printf ("%9ld", loops);
  44.     printf ("%12.2f Mb/s\n", (size * loops) / (lapse * 1e6 / 18.2));
  45. }
  46.  
  47. //--------------------------------------------------------------------------
  48. //
  49. //      Main program.
  50. //
  51. //      This prompts for a block size and a number of iterations, and then
  52. //      copies a block from real memory to XMS, from XMS to XMS, and from
  53. //      XMS back to real memory.  Each test is iterated the requested
  54. //      number of times, and mean timings are displayed for each test.
  55. //
  56. void main ()
  57. {
  58.     for (;;)
  59.     {
  60.         //--- Create XMS blocks of specified size
  61.         printf ("\nXMS timing test: %ld bytes of XMS available\n\n"
  62.                 "Enter XMS block size (0 to exit): ", XMS::available());
  63.         if (scanf ("%ld", &size) == 0 || size < 0 || size > UINT_MAX)
  64.         {   while (getchar() != '\n')
  65.                 continue;
  66.             printf ("Value between 0 and %u required; try again!\n", UINT_MAX);
  67.             continue;
  68.         }
  69.         if (size == 0)
  70.             break;
  71.         if ((size & 1) == 1)
  72.             printf ("Odd size: rounding down to %ld bytes\n", (size &= ~1));
  73.         XMS a(size), b(size);
  74.         if (!a || !b)
  75.         {   fprintf (stderr, "Not enough XMS (request = %ld bytes)\n", size);
  76.             continue;
  77.         }
  78.  
  79.         //--- Create conventional array of specified size
  80.         char* c = new char[size];
  81.         if (c == 0)
  82.         {   fprintf (stderr, "Not enough real memory (request = %u bytes)\n",
  83.                      unsigned (size));
  84.             continue;
  85.         }
  86.     
  87.         //--- Display headings
  88.         printf ("Transferring %u bytes; each test takes 5 seconds.\n",
  89.                 unsigned(size));
  90.         printf ("\n                Iterations  Transfer rate\n");
  91.     
  92.         long ticks, i;
  93.  
  94.         //--- Copy real memory to XMS
  95.         printf ("Real -> XMS:  ");
  96.         ticks = *timer + lapse;
  97.         for (i = 0; *timer < ticks; i++)
  98.             XMS::copy (a[0], c, size);
  99.         stats (i);
  100.  
  101.         //--- Copy XMS to XMS
  102.         printf ("XMS  -> XMS:  ");
  103.         ticks = *timer + lapse;
  104.         for (i = 0; *timer < ticks; i++)
  105.             XMS::copy (b[0], a[0], size);
  106.         stats (i);
  107.     
  108.         //--- Copy XMS to real memory
  109.         printf ("XMS  -> Real: ");
  110.         ticks = *timer + lapse;
  111.         for (i = 0; *timer < ticks; i++)
  112.             XMS::copy (c, b[0], size);
  113.         stats (i);
  114.  
  115.         //--- Delete real memory block
  116.         delete c;
  117.     }
  118. }
  119.